#include"CircularQueue.h"
MyCircularQueue* MyCircularQueueCreate(int k)
{
	MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
	obj->a = (int*)malloc(sizeof(int) * (k + 1));
	obj->head = obj->tail = 0;
	obj->k = k;
	return obj;
}
bool MyCircularQueueIsEmpty(MyCircularQueue* obj)
{
	return obj->head == obj->tail;
}
bool MyCircularQueueIsFull(MyCircularQueue* obj)
{
	return (obj->tail + 1 + obj->k + 1) % (obj->k + 1);
}
bool MyCircularQueueEn(MyCircularQueue* obj, int x)
{
	if (MyCircularQueueIsFull(obj))
		return false;
	obj->a[obj->tail] = x;
	obj->tail++;
	obj->tail %= (obj->k + 1);
	return true;
}
bool MyCircularQueueDe(MyCircularQueue* obj, int x)
{
	if (MyCircularQueueIsEmpty(obj))
		return false;
	obj->head++;
	obj->head %= (obj->k + 1);
	return true;
}
int MyCircularQueueFront(MyCircularQueue* obj)
{
	if (MyCircularQueueIsEmpty(obj))
		return -1;
	else
		return obj->a[obj->head];
}
int MyCircularQueueBack(MyCircularQueue* obj)
{
	if (MyCircularQueueIsEmpty(obj))
		return -1;
	else
		return obj->a[(obj->tail - 1 + obj->k + 1) % (obj->k + 1)];
}
void MyCircularQueueDestrot(MyCircularQueue* obj)
{
	free(obj->a);
	free(obj);
}